package cn.chen.sparkproject.spark;

import scala.math.Ordered;

import java.io.Serializable;

public class CategorySortKey implements Ordered<CategorySortKey>, Serializable{

    private static final long serialVersionUID = 8589588557633379641L;
    private long clickCount;
    private long orderCount;
    private long payCount;

    public CategorySortKey(long clickCount, long orderCount, long payCount) {
        this.clickCount = clickCount;
        this.orderCount = orderCount;
        this.payCount = payCount;
    }

    public long getClickCount() {
        return clickCount;
    }

    public void setClickCount(long clickCount) {
        this.clickCount = clickCount;
    }

    public long getOrderCount() {
        return orderCount;
    }

    public void setOrderCount(long orderCount) {
        this.orderCount = orderCount;
    }

    public long getPayCount() {
        return payCount;
    }

    public void setPayCount(long payCount) {
        this.payCount = payCount;
    }

    @Override
    public int compare(CategorySortKey that) {
        return 0;
    }

    @Override
    public boolean $less(CategorySortKey other) {
        if(clickCount < other.clickCount){
            return true;
        } else if(clickCount == other.clickCount && orderCount < other.orderCount){
            return true;
        } else if(clickCount == other.clickCount &&
                orderCount == other.orderCount &&
                payCount < other.payCount){
            return true;
        }
        return false;
    }

    @Override
    public boolean $greater(CategorySortKey other) {
        if(clickCount > other.clickCount){
            return true;
        } else if(clickCount == other.clickCount && orderCount > other.orderCount){
            return true;
        } else if(clickCount == other.clickCount &&
                  orderCount == other.orderCount &&
                  payCount > other.payCount){
            return true;
        }
        return false;
    }

    @Override
    public boolean $less$eq(CategorySortKey other) {
        if($less(other)){
            return true;
        } else if (clickCount == other.clickCount &&
                orderCount == other.orderCount &&
                payCount == other.payCount){
            return true;
        }
        return false;
    }

    @Override
    public boolean $greater$eq(CategorySortKey other) {
        if($greater(other)){
            return true;
        } else if (clickCount == other.clickCount &&
                orderCount == other.orderCount &&
                payCount == other.payCount){
            return true;
        }
        return false;
    }

    @Override
    public int compareTo(CategorySortKey other) {
        if(clickCount - other.clickCount != 0){
            return (int)(clickCount - other.clickCount);
        }else if(orderCount - other.orderCount != 0){
            return (int)(orderCount - other.orderCount);
        }else if(payCount - other.payCount != 0){
            return (int)(payCount - other.payCount);
        }
        return 0;
    }
}
